<?php 
namespace Modules\ShopAdmin\Http\Controllers\v1;
use Illuminate\Http\Request;
use Modules\AuthAdmin\Services\CommonService;
use Modules\AuthAdmin\Http\Requests\CommonIdRequest;
use Modules\AuthAdmin\Http\Requests\CommonStatusRequest;
use Modules\AuthAdmin\Http\Requests\CommonSortRequest;
use Modules\ShopAdmin\Models\ShopPicture as ShopPictureModel;
class PictureController extends CommonController
{ 
	/**
	 * @name  图片管理
	 * @method  GET	
	 * @param  page int 页码
	 * @param  pagesize int 每页条数	
	 * @param  the_jump int 是否跳转:0=否,1=跳转网页,2=跳转小程序页面,3=跳转详情		
	 * @param  type int 图片类型:1=首页轮播图,2=咨询轮播图,3=首页广告图	
	 * @param  status int 状态:0=禁用,1=启用	
	 * @param  created_at string 创建时间	
	 * @param  updated_at string 更新时间	
	 * @return  JSON
	 */
    public function index(Request $request)
    {
		return (new ShopPictureModel())->list_data($request->all());
    }
	/**
	 * @name  添加
	 * @method  POST	
	 * @param  image_id int 图片id	
	 * @param  url string 跳转链接	
	 * @param  the_jump int 是否跳转:0=否,1=跳转网页,2=跳转小程序页面,3=跳转详情
	 * @param  content string 详情
	 * @param  sort int 排序	
	 * @return  JSON
	 */
    public function store(Request $request)
    {
		$data = $request->all();
		$data['content'] = (new CommonService())->remve_pic_url($data['content']);
		return (new ShopPictureModel())->common_create($data);
    }
	/**
	 * @name  编辑页面
	 * @method  GET	
	 * @param  id int 轮播图ID	
	 * @return  JSON
	 */
    public function edit(CommonIdRequest $request)
    {
		return (new ShopPictureModel())->get_edit($request->get('id'));
    }
	/**
	 * @name  编辑提交
	 * @method  PUT	
	 * @param  id int 轮播图id
	 * @param  image_id int 图片id	
	 * @param  url string 跳转链接	
	 * @param  the_jump int 是否跳转:0=否,1=跳转网页,2=跳转小程序页面,3=跳转详情
	 * @param  type int 图片类型:1=首页轮播图,2=咨询轮播图,3=首页广告图	
	 * @param  content string 详情
	 * @param  sort int 排序		
	 * @return  JSON
	 */ 
    public function update(Request $request)
    {
		$data = $request->all();
		return (new ShopPictureModel())->common_update($data['id'],[
			'image_id'=>$data['image_id'],
			'url'=>$data['url'],
			'the_jump'=>$data['the_jump'],
			'type'=>$data['type'],
			'content'=>(new CommonService())->remve_pic_url($data['content']),
			'sort'=>$data['sort'],
			'title'=>$data['title']
		]); 
    }
	/**
	 * @name  调整状态
	 * @method  PUT	
	 * @param  id int 轮播图
	 * @param  status int 状态（0或1）
	 * @return  JSON
	 */ 
    public function status(CommonStatusRequest $request)
    {
		$data = $request->all();
		return (new ShopPictureModel())->common_status_update($data['id'],['status'=>$data['status']]); 
    }
	/**
	 * @name  是否往期
	 * @method  PUT	
	 * @param  id int 轮播图
	 * @param  open int 状态（0或1）
	 * @return  JSON
	 */ 
    public function open(Request $request)
    {
		$data = $request->all();
		return (new ShopPictureModel())->common_status_update($data['id'],['open'=>$data['open']]); 
    }
	/**
	 * @name  排序
	 * @method  PUT	
	 * @param  id int 轮播图
	 * @param  sort int 排序
	 * @return  JSON
	 */ 
    public function sorts(CommonSortRequest $request)
    {
		$data = $request->all();
		return (new ShopPictureModel())->common_sort_update($data['id'],['sort'=>$data['sort']]); 
    }
	
	/**
	 * @name  删除
	 * @method  DELETE	
	 * @param  id int 轮播图
	 * @return  JSON
	 */
    public function destroy(CommonIdRequest $request)
    {
		return (new ShopPictureModel())->common_destroy($request->get('id'));
    }
	
	
	
	
	
	
}
